package com.hydra.cron.server.model;

import com.google.common.base.Strings;

/**
 * Created by lee on 15/12/21.
 * zookeeper server服务器节点树实例
 */
public class CronServer {
    private String token;//实例唯一标识

    private String jobName;//任务名

    private String hostName;//hostname

    private ServerStatus status;//服务状态

    private int processSuccessCount;//统计一段时间内处理成功的次数

    private int processFailureCount;//统计一段时间内处理失败的次数

    private boolean leader;//是否是主

    private boolean leaderStoped;//停止作业的标记

    public CronServer() {
    }

    public enum ServerStatus {
        READY,
        RUNNING,
        DISABLED,
        STOPED,
        CRASHED;

        public static ServerStatus getServerStatus(final String status, final boolean disabled, final boolean stoped) {
            if (Strings.isNullOrEmpty(status)) {
                return ServerStatus.CRASHED;
            }
            if (disabled) {
                return ServerStatus.DISABLED;
            }
            if (stoped) {
                return ServerStatus.STOPED;
            }
            return ServerStatus.valueOf(status);
        }
    }

    public String getJobName() {
        return jobName;
    }

    public void setJobName(String jobName) {
        this.jobName = jobName;
    }

    public String getHostName() {
        return hostName;
    }

    public void setHostName(String hostName) {
        this.hostName = hostName;
    }

    public ServerStatus getStatus() {
        return status;
    }

    public void setStatus(ServerStatus status) {
        this.status = status;
    }

    public int getProcessSuccessCount() {
        return processSuccessCount;
    }

    public void setProcessSuccessCount(int processSuccessCount) {
        this.processSuccessCount = processSuccessCount;
    }

    public int getProcessFailureCount() {
        return processFailureCount;
    }

    public void setProcessFailureCount(int processFailureCount) {
        this.processFailureCount = processFailureCount;
    }

    public boolean isLeader() {
        return leader;
    }

    public void setLeader(boolean leader) {
        this.leader = leader;
    }

    public boolean isLeaderStoped() {
        return leaderStoped;
    }

    public void setLeaderStoped(boolean leaderStoped) {
        this.leaderStoped = leaderStoped;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    @Override
    public String toString() {
        return "JobServer{" +
                "token='" + token + '\'' +
                ", jobName='" + jobName + '\'' +
                ", hostName='" + hostName + '\'' +
                ", status=" + status +
                ", processSuccessCount=" + processSuccessCount +
                ", processFailureCount=" + processFailureCount +
                ", leader=" + leader +
                ", leaderStoped=" + leaderStoped +
                '}';
    }
}
